package com.shujia.spark.mllib

import org.wltea.analyzer.core.{IKSegmenter, Lexeme}

import java.io.StringReader
import scala.collection.mutable.ListBuffer

object Demo8IKUtils {
  def main(args: Array[String]): Unit = {
    val text = "起吧，生活的这么捉襟见肘的，有啥资格赖床？！";
    val list: List[String] = fit(text)
    println(list)
  }

  def fit(text: String): List[String] = {
    val listBuffer = new ListBuffer[String]

    val sr = new StringReader(text);
    val ik = new IKSegmenter(sr, true);
    //读取第一次词
    var lex: Lexeme = ik.next();
    while (lex != null) {
      listBuffer += lex.getLexemeText
      //读取下一个词
      lex = ik.next()
    }

    listBuffer.toList
  }

}
